<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/jsp/manage/common/taglibs.jsp" %>

<div>
    <form id="manage_merchant_editform"
          action="${pageContext.request.contextPath}/manage/merchant/merchant/${action=='create'?'saveJson':'updateJson'}.html"
          method="post">
        <jodd:form bean="merchant" scope="request">
            <input name="id" type="hidden" value="${merchantEntity.id}"/>
            <input name="merchantId" type="hidden" value="${merchantEntity.merchantId}">
            <table class="tableForm" width="100%" id="merchant_table">
                <tr>
                    <th>商户类型：</th>
                    <td>
                        <select name="merchantType" id="merchantType" editable="false" style="height:27px;"
                                onchange="changeInputText()"
                                panelHeight="auto" class="easyui-combobox" data-options="required:true"
                                validType="merchantType">
                            <c:forEach items="${merchantTypes}" var="e">
                                <c:if test="${merchantTag == 'agent' || merchantTag == 'agentAccount' ||merchantTag == 'normalAccount'}">
                                    <c:if test="${merchantEntity.merchantType == e.key}">
                                        <option value="${e.key}">${e.value}</option>
                                    </c:if>
                                </c:if>
                                <c:if test="${merchantTag != 'agent' && merchantTag != 'agentAccount'&& merchantTag != 'normalAccount'}">
                                    <option value="${e.key}"
                                            <c:if test="${merchantEntity.merchantType == e.key}">
                                                selected
                                            </c:if>
                                    >${e.value}</option>
                                </c:if>
                            </c:forEach>
                        </select>
                </tr>
                <c:if test="${merchantTag != 'agentAccount'}">
                    <tr id="parentMerchantId_tr">
                        <th>上级商户ID：</th>
                        <td><input type="text" id="parentMerchantId" name="parentMerchantId" size="48"
                                   class="easyui-validatebox text"
                                   value="${action !='create'? merchantEntity.parentMerchantId:parentMerchantId}"
                                   validType="byteLength[1,20]" placeholder="代理商户添加请填写"
                                   <c:if test="${(merchantTag == 'agent'|| merchantTag == 'normalAccount') && action !='create'}">readonly</c:if>/></td>
                    </tr>
                </c:if>
                <tr>
                    <th>商户名称：</th>
                    <td><textarea rows="3" cols="40" style="width:300px;" name="merchantName" class="easyui-validatebox"
                                  data-options="required:true"
                                  validType="byteLength[1,256]">${merchantEntity.merchantName}</textarea></td>
                </tr>
                <tr>
                    <th>联系人：</th>
                    <td><input type="text" name="contact" size="48" class="easyui-validatebox text"
                               value="${merchantEntity.contact}" data-options="required:true"
                               validType="byteLength[1,32]"/></td>
                </tr>
                <tr>
                    <th>手机号：</th>
                    <td><input type="text" name="mobile" size="48" class="easyui-validatebox mobile"
                               value="${merchantEntity.mobile}" data-options="required:true"
                               validType="byteLength[1,18]"/></td>
                </tr>
                <tr>
                    <th>邮箱：</th>
                    <td><input type="text" name="email" size="48" class="easyui-validatebox text"
                               value="${merchantEntity.email}" data-options="required:true"
                               validType="byteLength[1,128]"/></td>
                </tr>
                <tr>
                    <th>营业执照号：</th>
                    <td><input type="text" name="licenceNo" size="48" class="easyui-validatebox text"
                               value="${merchantEntity.licenceNo}"
                               validType="byteLength[1,128]"/></td>
                </tr>
                <tr>
                    <th>地址：</th>
                    <td><textarea rows="3" cols="40" style="width:300px;" name="address" class="easyui-validatebox"
                                  validType="byteLength[1,512]">${merchantEntity.address}</textarea></td>
                </tr>
                <tr>
                    <th>营业执照图片地址：</th>
                    <td><textarea rows="3" cols="40" style="width:300px;" name="licencePath" class="easyui-validatebox"
                                  validType="byteLength[1,256]">${merchantEntity.licencePath}</textarea></td>
                </tr>
                <tr>
                    <th>经营商品：</th>
                    <td><textarea rows="3" cols="40" style="width:300px;" name="goods" class="easyui-validatebox"
                                  validType="byteLength[1,1024]">${merchantEntity.goods}</textarea></td>
                </tr>
                <tr>
                    <th>经营范围：</th>
                    <td><textarea rows="3" cols="40" style="width:300px;" name="busScope" class="easyui-validatebox"
                                  validType="byteLength[1,512]">${merchantEntity.busScope}</textarea></td>
                </tr>
                <tr>
                    <th>经营类目：</th>
                    <td><textarea rows="3" cols="40" style="width:300px;" name="category" class="easyui-validatebox"
                                  validType="byteLength[1,512]">${merchantEntity.category}</textarea></td>
                </tr>
                <tr>
                    <th>法人姓名：</th>
                    <td><textarea rows="3" cols="40" style="width:300px;" name="legalName" class="easyui-validatebox"
                                  validType="byteLength[1,512]">${merchantEntity.legalName}</textarea></td>
                </tr>
                <tr>
                    <th>法人证件号：</th>
                    <td><input type="text" name="legalCertNo" size="48" class="easyui-validatebox text"
                               value="${merchantEntity.legalCertNo}"
                               validType="byteLength[1,32]"/></td>
                </tr>
                <tr>
                    <th>法人证件类型：</th>
                    <td>
                        <select name="legalCertType" id="legalCertType" editable="false" style="height:27px;"
                                panelHeight="auto" class="easyui-combobox"
                                data-options="required:true">
                            <c:forEach items="${certTypes}" var="e">
                                <option value="${e.key}"
                                        <c:if test="${merchantEntity.legalCertType == e.key}">
                                            selected
                                        </c:if>
                                >${e.value}</option>
                            </c:forEach>
                        </select>
                </tr>
                <tr>
                    <th>法人证件正面图片地址：</th>
                    <td><textarea rows="3" cols="40" style="width:300px;" name="legalCertFrontPath"
                                  class="easyui-validatebox"
                                  validType="byteLength[1,256]">${merchantEntity.legalCertFrontPath}</textarea></td>
                </tr>
                <tr>
                    <th>法人证件反面图片地址：</th>
                    <td><textarea rows="3" cols="40" style="width:300px;" name="legalCertBackPath"
                                  class="easyui-validatebox"
                                  validType="byteLength[1,256]">${merchantEntity.legalCertBackPath}</textarea></td>
                </tr>
                <tr>
                    <th>法人证件到期时间：</th>
                    <td><input type="text" name="法人证件到期时间" size="48" class="easyui-validatebox text"
                               value="${merchantEntity.legalCertValidDate}"
                               validType="byteLength[1,32]"/></td>
                </tr>
                <tr>
                    <th>银行编码：</th>
                    <td>
                        <select name="bankCode" id="bankCode" editable="false" style="height:27px;"
                                panelHeight="auto" class="easyui-combobox"
                                data-options="required:true">
                            <c:forEach items="${bankCodes}" var="e">
                                <option value="${e.key}"
                                        <c:if test="${merchantEntity.bankCode == e.key}">
                                            selected
                                        </c:if>
                                >${e.value}</option>
                            </c:forEach>
                        </select>
                </tr>
                <tr>
                    <th>银行账户类型：</th>
                    <td>
                        <select name="bankAccountType" id="bankAccountType" editable="false" style="height:27px;"
                                panelHeight="auto" class="easyui-combobox"
                                data-options="required:true">
                            <c:forEach items="${publicTags}" var="e">
                                <option value="${e.key}"
                                        <c:if test="${merchantEntity.bankAccountType == e.key}">
                                            selected
                                        </c:if>
                                >${e.value}</option>
                            </c:forEach>
                        </select>
                </tr>
                <tr>
                    <th>银行卡账户名：</th>
                    <td><input type="text" name="bankCardName" size="48" class="easyui-validatebox text"
                               value="${merchantEntity.bankCardName}"
                               validType="byteLength[1,64]"/></td>
                </tr>
                <tr>
                    <th>银行卡号：</th>
                    <td><input type="text" name="bankCardNo" size="48" class="easyui-validatebox text"
                               value="${merchantEntity.bankCardNo}"
                               validType="byteLength[1,64]"/></td>
                </tr>
                <tr>
                    <th>银行卡类型：</th>
                    <td>
                        <select name="bankCardType" id="bankCardType" editable="false" style="height:27px;"
                                panelHeight="auto" class="easyui-combobox"
                                data-options="required:true">
                            <c:forEach items="${bankCardTypes}" var="e">
                                <option value="${e.key}"
                                        <c:if test="${merchantEntity.bankCardType  == e.key}">
                                            selected
                                        </c:if>
                                >${e.value}</option>
                            </c:forEach>
                        </select>
                </tr>
                <tr>
                    <th>开户省：</th>
                    <td><input type="text" name="bankProvince" size="48" class="easyui-validatebox text"
                               value="${merchantEntity.bankProvince}"
                               validType="byteLength[1,64]"/></td>
                </tr>
                <tr>
                    <th>开户市：</th>
                    <td><input type="text" name="bankCity" size="48" class="easyui-validatebox text"
                               value="${merchantEntity.bankCity}"
                               validType="byteLength[1,64]"/></td>
                </tr>
            </table>
        </jodd:form>
    </form>
</div>

<script type="text/javascript">

    $("#merchantType").combobox({
        onChange: function (n, o) {
            changeInputText(n);
        }
    });

    function changeInputText() {
        if ('AGENT_MERCHANT' == $('input[name="merchantType"]').val()) {
            $('#parentMerchantId').val("");
            $('#parentMerchantId_tr').hide();
        } else {
            $('#parentMerchantId_tr').show();
        }
    }

    $.extend($.fn.validatebox.defaults.rules, {
        merchantType: {
            validator: function () {
                if ('NORMAL_MERCHANT' == $('input[name="merchantType"]').val()) {
                    var parentMerchantId = $('#parentMerchantId').val();
                    if (parentMerchantId == null || parentMerchantId == '') {
                        return false;
                    }
                }
                return true;
            },
            message: '普通商户注册,必须填写[上级商户ID].'
        }
    });
</script>
